package com.jeff.tianti.cms.dao;

import com.jeff.tianti.common.dao.CustomBaseSqlDaoImpl;
import com.jeff.tianti.common.entity.PageModel;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import com.jeff.tianti.cms.entity.Leader;
import com.jeff.tianti.cms.dto.LeaderQueryDTO;
import org.apache.commons.lang3.StringUtils;

/**
 * @author NOW_GO
 * @desc LeaderDaoImpl类
 * @date 2019-07-12
 */

public class LeaderDaoImpl extends CustomBaseSqlDaoImpl implements LeaderDaoCustom {

    public PageModel<Leader> queryLeaderPage(LeaderQueryDTO leaderQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from Leader t  where t.deleteFlag=0");

        if (leaderQueryDTO != null) {
            String position = leaderQueryDTO.getPosition();
            if (StringUtils.isNotBlank(position)) {
                hql.append(" and t.position like :position ");
                map.put("position", "%" + position + "%");
            }
            String name = leaderQueryDTO.getName();
            if (StringUtils.isNotBlank(name)) {
                hql.append(" and t.name like :name ");
                map.put("name", "%" + name + "%");
            }
        }
        hql.append(" order by t.sort ");

        return this.queryForPageWithParams(hql.toString(), map, leaderQueryDTO.getCurrentPage(), leaderQueryDTO.getPageSize());
    }

    public List<Leader> queryLeaderList(LeaderQueryDTO leaderQueryDTO) {
        Map<String, Object> map = new HashMap<String, Object>();
        StringBuilder hql = new StringBuilder();
        hql.append("select t from Leader t where t.deleteFlag=0 ORDER BY t.sort");

        return this.queryByMapParams(hql.toString(), map);
    }


}